#ifndef _CENTERJUDGE_MAMANAGER_H_
#define _CENTERJUDGE_MAMANAGER_H_

#include "Common.h"
#include "Resource.h"
#include "ResourceManager.h"
#include "Singleton.h"
#include "String.h"
#include "Database/Field.h"
#include "DataManager.h"

#include "Threading/Mutex.h"

#define DB_NAME_CENTERJUDGE		"center_judge"

class CharPtr;
class Database;
class WorldPacket;
class WSSocketPtr;

typedef struct center_judge_tag_
{
	uint32 judge_id;		//评价ID
	uint32 status;			//状态
	uint32 type;			//类型
	uint32 pid;				//被评价人PID
	String nickname;		//昵称
	String icon_url;		//头像
	uint32 target_id;		//目标ID
	uint32 target_type;		//目标类型
	uint32 judge_pid;		//评价人PID
	String judge_nickname;	//评价人昵称
	String judge_icon_url;	//评价人头像
	uint32 judge_level;		//评价星级（1-5星）
	uint32 label_id;		//标签ID
	String label_info;		//评价列表
	
	String judge_info;		//评价内容
	
	uint32 create_time;		//创建时间
	
	double coord_latitude;	//纬度
	double coord_longitude;	//精度
	double coord_altitude;	//海拔
	
	center_judge_tag_()
	{
		Init();
	}
	
	void Init()
	{
		judge_id = 0;
		status = 0;
		type = 0;
		pid = 0;
		nickname = "";
		icon_url = "";
		target_id = 0;
		target_type = 0;
		judge_pid = 0;
		judge_nickname = "";
		judge_icon_url = "";
		judge_level = 0;
		label_id = 0;
		label_info = "";
		
		judge_info = "";
		create_time = 0;
		
		coord_latitude = 0.0;
		coord_longitude = 0.0;
		coord_altitude = 0.0;
	}
	
}CenterJudge;


#define WGS_CENTERJUDGE_MUTEX_NAME centerjudge_mutex
#define WGS_CENTERJUDGE_MUTEX mutable boost::mutex WGS_CENTERJUDGE_MUTEX_NAME;
#define WGS_CENTERJUDGE_LOCK		boost::lock_guard<boost::mutex> wgsCenterJudgeMutexLock(WGS_CENTERJUDGE_MUTEX_NAME);

//-------------------------组局信息-----------------------
class  SERVER_DECL CenterJudgeManager:public Singleton<CenterJudgeManager>
{
public:
WGS_CENTERJUDGE_MUTEX
	/**
	 * @创建时间 2017-02-07
	 * @创建人 Roach
	 * @函数作用 添加一条CenterJudge记录
	 * @参数
	 * 	@cj	CenterJudge
	 */
	bool AddCenterJudge(CenterJudge & cj);
	
	/**
	 * @创建时间 2017-02-07
	 * @创建人 Roach
	 * @函数作用 更新CenterJudge数据
	 * @参数
	 * 	@cj CenterJudge
	 */
	bool UpdateCenterJudge(const CenterJudge & cj);
	
	/**
	 * @创建时间 2017-02-07
	 * @创建人 Roach
	 * @函数作用 更新CenterJudge数据
	 * @参数
	 * 	@cj_id	
	 *	@fields	字段键值对,格式：fields["key1"] = 1; fields["key2"] = 2;...
	 */
	bool UpdateCenterJudge(Fields * fields, const char * QueryString, ...);
	bool UpdateCenterJudge(const uint32 & cj_id, Fields * fields);
	
	/**
	 * @创建时间 2017-02-07
	 * @创建人 Roach
	 * @函数作用 根据judge_id获取一条PD数据
	 * @参数
	 *  @cj_id 	CenterJudge id
	 * 	@cj		CenterJudge对象
	 */
	bool GetCenterJudge(const uint32 & cj_id, CenterJudge * cj);
	
	/**
	 * @创建时间 2017-02-07
	 * @创建人 Roach
	 * @函数作用 获取记录列表
	 * @参数
	 * 	@lstData	CenterJudge对象列表
	 *  @query 查询语句条件
	 */
	uint32 GetCenterJudgeList(std::list<CenterJudge> * lstData, const char * query,...);
	// 获得评价列表
	bool GetjudgeList(std::list<CenterJudge> * lstCJ, const uint32 & pid, const uint32 & offset, const uint8 & num);
public:
	
	//========================逻辑操作相关===================================
	// 玩家对玩家进行评价
	uint8 PlayerJudge(CharPtr & pChr, const uint32 & target_id, const uint32 & target_type, const uint32 & pid, const uint32 & judge_pid, const uint8 & level, std::vector<uint8> vLabel, String judge_info);
	// 获得玩家组局评价过的玩家列表
	std::vector<uint32> GetJudgedCenterBattlePidList(CharPtr & pChr, const uint32 & pid, const uint32 & target_id, const uint32 & target_type);
	//========================逻辑操作相关===================================
	
};

#define	 sCenterJudgeMgr		 CenterJudgeManager::getSingleton()

#endif	// _CENTERJUDGE_MAMANAGER_H_
